<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仓库WMS</title>
    <link rel="shortcut icon" href="favicon.ico">

    <script src="../../res/js/comm.js"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>实体仓库存列表 </h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>


        <div class="ibox-content">

            <div class="ibox-query">
                <div class="row">
                    <form id="stockForm" method="post" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-1 control-label"><span style="color:red">*</span>仓库编码</label>
                            <div class="col-sm-1">
                                <input id="warehouseCode" name="warehouseCode" class="form-control" type="text" >
                            </div>
                            <label class="col-sm-1 control-label">商品编码</label>
                            <div class="col-sm-1">
                                <input id="goodsCode" name="goodsCode" class="form-control" type="text" >
                            </div>
                            <label class="col-sm-1 control-label">商品名称</label>
                            <div class="col-sm-2">
                                <input id="goodsName" name="goodsName" class="form-control" type="text" >
                            </div>
                            <label class="col-sm-1 control-label">可用库存</label>
                            <div class="col-sm-1">
                                <select data-placeholder="全部" name="usableStock" class="form-control">
                                    <option value="">全部</option>
                                    <option value="1">&gt;0</option>
                                    <option value="2">&lt;0</option>
                                    <option value="3">=0</option>
                                </select>
                            </div>

                            <div class="col-sm-3">
                                <button style="margin-left: 100px;" class="btn btn-info" onclick='$.openx.query()'
                                        type="button"><i class="glyphicon glyphicon-search"></i> 查询
                                </button>
                            </div>
                            <!--<label class="col-sm-1 control-label">应用URL</label>-->
                            <!--<div class="col-sm-2">-->
                            <!--<input name="" class="form-control" placeholder="请输入文本" type="text">-->
                            <!--</div>-->
                            <!--<label class="col-sm-1 control-label">创建时间</label>-->
                            <!--<div class="col-sm-2">-->
                            <!--<input name="" class="form-control" placeholder="请输入文本" type="text">-->
                            <!--</div>-->
                        </div>
                        <div class="hr-line-dashed"></div>
                    </form>
                </div>
            </div>

            <div class="row row-lg">
                <div class="col-sm-12">
                    <div id="StockBar"></div>
                    <table id="table" data-show-export="true">
                        <thead>
                        <tr>
                            <th data-align="center" data-field="_checkbox_status" data-checkbox="true"></th>
                            <th data-align="center"  data-field="id"
                                data-formatter="$.openx.generatorId"> 序号
                            </th>

                            <th data-align="center" data-field="warehouseCode">仓库编码</th>
                            <th data-align="center" data-field="goodsCode">商品编码</th>
                            <th data-align="center" data-field="goodsName">商品名称</th>
                            <th data-align="center" data-field="usableStock" data-formatter="formatUsableStock">可用库存</th>
                            <th data-align="center" data-field="stock">库存</th>
                            <th data-align="center" data-field="occupyStock" data-formatter="occupyStockFormat">预占库存</th>
                            <th data-align="center" data-field="stockReserved">库存中心预占</th>
                            <th data-align="center" data-field="stockModifyTime" data-formatter="timeDateFormat">库存修改时间</th>
                            <th data-align="center" data-field="occupyStockModifyTime" data-formatter="timeDateFormat">预占库存修改时间</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script type="text/html" id="stockDialog">
    <form class="form-horizontal" id="stockPartnerForm">

        <div class="col-md-12" style="width: 400px;margin-top: 20px">
            <div class="form-group" >
                <label class="col-sm-4 control-label"><font color="red" >* </font>仓库编码：</label>
                <div class="col-sm-8">
                    <input name="warehouseCode" id="warehouseCodeInsert" class="form-control" placeholder="请输入仓库编码" type="text" title="必填字段" required="true" value="{{!d.warehouseCode ? '':d.warehouseCode}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label"><font color="red" >* </font>商品编码：</label>
                <div class="col-sm-8">
                    <input name="goodsCode" id="goods_code" class="form-control" placeholder="请输入商品编码" type="text"  title="必填字段" required="true" value="{{!d.goodsCode ? '':d.goodsCode}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">库存数量：</label>
                <div class="col-sm-8">
                    <input name="stock" id="stock" class="form-control" placeholder="请选择库存数量" type="text" required="true" value="{{!d.stock ? '':d.stock}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label">预占库存：</label>
                <div class="col-sm-8">
                    <input name="occupyStock" id="occupyStock" class="form-control" placeholder="请输入预占库存" type="text" value="{{!d.occupyStock ? '':d.occupyStock}}">
                </div>
            </div>

        </div>
    </form>
</script>

<!-- 预占库存详情 -->
<script type="text/html" id="occupyStockDetail">
    <div class="ibox-content">
            <div class="ibox-query">
                <div class="row">
                    <form id="occupyStockForm" method="post" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">订单编码</label>
                            <div class="col-sm-3">
                                <input id="orderCode2" name="orderCode2" class="form-control" type="text">
                                <input id="wh_code" type="hidden"/>
                                <input id="gs_code" type="hidden"/>
                            </div>

                            <div class="col-sm-3">
                                <button style="margin-left: 100px;" class="btn btn-info" onclick='queryOccupyDetailByOrderCode()'
                                        type="button"><i class="glyphicon glyphicon-search"></i> 查询
                                </button>
                            </div>
                        
                        </div>
                        <div class="hr-line-dashed"></div>
                    </form>
                </div>
            </div>

            <div class="row row-lg">
                <div class="col-sm-12">
                    <table id="occupyTable" data-show-export="true">
                        <thead>
                        <tr>
                            <th data-align="center"  data-field="id"
                                data-formatter="$.openx.generatorId"> 序号
                            </th>

                            <th data-align="center" data-field="orderCode">订单编码</th>
                            <th data-align="center" data-field="topChannelCode">订单渠道</th>
                            <th data-align="center" data-field="state">订单状态</th>
                            <th data-align="center" data-field="createTime" data-formatter="timeDateFormat">下单时间</th>
                            <th data-align="center" data-field="quantity">占用数量</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
    </div>
</script>

<script>

    /**查询参数信息*/
    var url = "/openx/wms/physicalWMSService/queryStockForPage";
    //对应接口入参
    var param = {};

    var formId = 'stockForm';

    (function () {
        /**设置增删改查的工具条*/
        //$.openx.setTableToolBar('StockBar');
        /**进行表格数据初始化*/
        var data = $.openx.getJsonObj(formId);
        param.bean = data;
        param.bean.warehouseCode = 'fdsa1212xxvcxv';
        $.openx.initTable("table", url, param);

    })();

    function timeDateFormat(value) {
        console.log(value)
        return !value ? "-" : new Date(value).format("yyyy-MM-dd hh:mm")
    }

    $.openx.insert = function () {
        var createForm = "stockPartnerForm";
        var innerHtml = $.openx.innerHtml('stockDialog');
        laytpl(innerHtml).render({}, function (html) {
            $.openx.openLayer(['auto', 'auto'], '新增实体仓库', html, false, function () {
                if ($.openx.validation(createForm)) {
                    //获取表单数据
                    var param = $.openx.getJsonObj(createForm);
                    $X("/boss/wms/physicalWMSService", "createStock").callx({
                        param: param,
                        onResult: function (data) {
                            if (data) {
                                $.openx.tableRefresh(null, null, true);
                                layer.closeAll();
                                layer.msg("新增成功");
                            }
                        },
                        onError: function (error) {
                            var res = JSON.parse(error);
                            layer.msg(res.message)
                        }
                    });
                }
            });
        })


    }

    $.openx.update = function () {
        $.openx.onClickUpdate(function (rows) {
            console.log(rows)
        })
    }


    $.openx.delete = function () {
        $.openx.onClickDelete(function (rows) {
            console.log(rows)
        })
    }

    $.openx.query = function () {
        $.openx.tableId = '#table';
        var data2 = $.openx.getJsonObj(formId);
        param.bean = data2;
        if(!data2.warehouseCode) {
            layer.msg('请输入仓库编码');
            return ;
        }
        var queryTimeStamp = new Date();
        $.openx.tableRefresh(url+"?t="+queryTimeStamp.getTime(), param);
    }

    function formatUsableStock(value, row) {
        return row.stock - row.occupyStock -row.stockReserved;
    }


    function occupyStockFormat(value, row){
        if(value){
            return "<a   style = '\color:#000000;text-decoration:underline;\' onclick='javascript:queryOccupyStockDetail(" + JSON.stringify(row)+ ");'><b>"+row.occupyStock+"</b></a>";
        }
    }

    function queryOccupyStockDetail(row){
        $('#wh_code').val(row.warehouseCode);
        $('#gs_code').val(row.goodsCode);
        var queryUrl = "/openx/wms/physicalWMSService/queryOccupyStockDetail";
        //对应接口入参
        var queryParam = {};
        queryParam.warehouseCode =row.warehouseCode;
        queryParam.goodsCode = row.goodsCode;
        queryParam.orderCode = "";
        
        var html = $.openx.innerHtml('occupyStockDetail');



        $.openx.openLayer(['700','700'], '查询商品库存预占详情', html, true)

        $.openx.initTable("occupyTable", queryUrl, queryParam);
        
}

    function queryOccupyDetailByOrderCode(){
        var queryForm = 'occupyStockForm';

        var data = $.openx.getJsonObj(queryForm);
        var queryParam = {};
        queryParam.orderCode = data.orderCode2;
        queryParam.warehouseCode = data.warehouseCode;
        queryParam.goodsCode = data.goodsCode;
        var equryTimeStamp = new Date();
        var queryUrl = "/openx/wms/physicalWMSService/queryOccupyStockDetail";
        $.openx.tableRefresh(queryUrl+"?t="+equryTimeStamp.getTime(), queryParam);
    }

</script>


</html>
